{extend name="admin@index_layout"/}
{block name="main"}
<form class="layui-form" method="post">
    <input type="hidden" name="row[id]" value="{$data.id}" />
    <div class="layui-form-item" >
        <label class="layui-form-label">分配陪诊员</label>
        <div class="layui-input-block">
            <select name="row[pz_id]">
                {if !empty($pz_list)}
                {foreach $pz_list as $key2}
                <option <?php if( $key2['id'] == $data['pz_id']){ ?>selected<?php }?>  value="{$key2.id}">{$key2.name}</option>
                {/foreach}
                {/if}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">省</label>
        <div class="layui-input-block">
            <select name="row[province]" id="ccc62" lay-verify="required" lay-filter="ccc62">
                <option value="">请选择省</option>
                {volist name="provice" id="vo"}
                <!--                <option  value="{$key.id}"  name="row[operate_type]">{$key.name}</option>-->
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['province']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">市</label>
        <div class="layui-input-block">
            <select id="c-city" name="row[city]" lay-verify="required" lay-filter="c-city">
                <option value="">请选择市</option>
                {volist name="city_list" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['city']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">区</label>
        <div class="layui-input-block">
            <select id="c-city2" name="row[area]"  lay-filter="c-city2">
                <option value="">请选择区</option>
                {volist name="area_list" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['area']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">医院</label>
        <div class="layui-input-block">
            <select id="c-hospita" name="row[hospital_id]" lay-verify="required"  lay-filter="c-hospita">
                <option value="">请选医院</option>
                {volist name="hospital_list" id="vo"}
                <option value="{$vo.id}"" <?php if( $vo['id'] == $data['hospital_id']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">预约医师</label>
        <div class="layui-input-block">
            <select id="c-doctor" name="row[doctor_id]" lay-filter="c-doctor">
                {if !empty($doctor_list)}
                {foreach $doctor_list as $key2}
                <option <?php if( $key2['id'] == $data['doctor_id']){ ?>selected<?php }?>  value="{$key2.id}">{$key2.name}</option>
                {/foreach}
                {/if}
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label ">预约时间</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input datetime" name="row[time]" value="{$data.time}" placeholder="预约时间">
        </div>
    </div>




<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">科室</label>-->
<!--        <div class="layui-input-block">-->
<!--            <select id="c-department" name="row[department_id]" lay-verify="required"  lay-filter="c-department">-->
<!--                <option value="">请选科室</option>-->
<!--                {volist name="department_list" id="vo"}-->
<!--                <option value="{$vo.id}" <?php if( $vo['id'] == $data['department_id']){ ?> selected <?php }?>>{$vo.name}</option>-->
<!--                {/volist}-->
<!--            </select>-->
<!--        </div>-->
<!--    </div>-->







    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit>立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['yznForm', 'laydate','form'], function () {
        var yznForm = layui.yznForm,
            laydate = layui.laydate;

        var form = layui.form;
        yznForm.bindevent($("form.layui-form"));

        laydate.render({
            elem: '#ID-laydate'
        });

        form.on('select(ccc6)', function (data) {
            console.log(data.value);
            if (data.value == 3) {
                $(".c5").show();
            } else{
                $(".c5").hide();
            }
            form.render();
        });


        form.on('select(ccc62)', function (data) {
            console.log(data.value);
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('getc_cate')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {

                        $("#c-city").empty();
                        var str = "<option value>请选择市</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.name + '>' + val.name + '</option>'
                        });
                        $("#c-city").append(str);

                        $("#c-city2").empty();
                        var str2 = "<option value>请选择区</option>";
                        $("#c-city2").append(str2);


                        $("#c-hospita").empty();
                        var str3 = "<option value>请选医院</option>";
                        $("#c-hospita").append(str3);


                        $("#c-department").empty();
                        var str4 = "<option value>请选科室</option>";
                        $("#c-department").append(str4);

                        $("#c-doctor").empty();
                        var str5 = "<option value>请选医师</option>";
                        $("#c-doctor").append(str5);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(c-city)', function (data) {
            var selectElement = document.getElementById("ccc62");
            var selectedValue = selectElement.value;
            let arr = ['北京市', '上海市', '天津市', '重庆市'];
            if (arr.includes(selectedValue)){
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('get_hospit2')}",//提交URL
                    data: {'id': data.value},//提交的数据
                    success: function (result) {
                        if (result.code == 200) {
                            $("#c-hospita").empty();
                            var str = "<option value>请选医院</option>";
                            $.each(result.data, function (i, val) {
                                str += '<option value=' + val.id + '>' + val.name + '</option>'
                            });
                            $("#c-hospita").append(str);

                            $("#c-department").empty();
                            var str4 = "<option value>请选科室</option>";
                            $("#c-department").append(str4);

                            $("#c-doctor").empty();
                            var str5 = "<option value>请选医师</option>";
                            $("#c-doctor").append(str5);

                            layui.form.render('select');
                        }
                    },
                    error: function () {
                        alert("获取信息失败")
                    }
                });
                form.render();
            }else{
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id': data.value},//提交的数据
                    success: function (result) {
                        if (result.code == 200) {

                            $("#c-city2").empty();
                            var str = "<option value>请选择区</option>";
                            $.each(result.data, function (i, val) {
                                str += '<option value=' + val.name + '>' + val.name + '</option>'
                            });
                            $("#c-city2").append(str);


                            $("#c-hospita").empty();
                            var str3 = "<option value>请选医院</option>";
                            $("#c-hospita").append(str3);


                            $("#c-department").empty();
                            var str4 = "<option value>请选科室</option>";
                            $("#c-department").append(str4);

                            $("#c-doctor").empty();
                            var str5 = "<option value>请选医师</option>";
                            $("#c-doctor").append(str5);

                            layui.form.render('select');
                        }
                    },
                    error: function () {
                        alert("获取信息失败")
                    }
                });
                form.render();
            }
        });

        form.on('select(c-city2)', function (data) {
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('get_hospit')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {
                        $("#c-hospita").empty();
                        var str = "<option value>请选医院</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.id + '>' + val.name + '</option>'
                        });
                        $("#c-hospita").append(str);

                        $("#c-department").empty();
                        var str4 = "<option value>请选科室</option>";
                        $("#c-department").append(str4);

                        $("#c-doctor").empty();
                        var str5 = "<option value>请选医师</option>";
                        $("#c-doctor").append(str5);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(c-hospita)', function (data) {
            console.log(data);
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('get_department')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {
                        $("#c-department").empty();
                        var str = "<option value>请选科室</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.id + '>' + val.name + '</option>'
                        });
                        $("#c-department").append(str);
                        layui.form.render('select');

                        $("#c-doctor").empty();
                        var str5 = "<option value>请选医师</option>";
                        $("#c-doctor").append(str5);
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

    });
</script>
{/block}